package com.hissagetest;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class HelloBroadcastRecv extends BroadcastReceiver {
	private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
	private static Activity curActivity = null;
	
	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(SMS_RECEIVED)) {
			if (intent.getExtras() != null) {
				
				if (curActivity == null) {
					HelloSms.onStaticSmsReceive(intent) ;
					return ;
				}
				
				if (curActivity.getClass() == HelloAndroidActivity.class) {
					((HelloAndroidActivity)curActivity).onSmsReceive(intent) ;
				} else if (curActivity.getClass() == HelloSms.class) {
					((HelloSms)curActivity).onSmsReceive(intent) ;
				} else {
					Log.e("HelloBroadcastRecv", "fatal error: the curActivity class is a error type") ;
				}
			}
		}
	}
	
	public static void setCurActivity(Activity act) {
		curActivity = act ;
	}
}
